package point

import (
	"os/exec"
	"strings"
)

type WanXMacPoint struct {
	index int
}

func NewWanXMacPoint() *WanXMacPoint { return &WanXMacPoint{} }

func (s *WanXMacPoint) Get() any {
	var interfaceName string

	if s.index == 0 {
		interfaceName = "eth1"
	} else if s.index == 1 {
		interfaceName = "eth2"
	} else {
		return ""
	}

	getInterfaceMac := func(iface string) string {
		cmd := exec.Command("cat", "/sys/class/net/"+iface+"/address")
		output, err := cmd.Output()
		if err != nil {
			return ""
		}

		return strings.TrimSuffix(string(output), "\n")
	}

	return getInterfaceMac(interfaceName)
}

func (s *WanXMacPoint) Set(...any) bool { return false }

func (s *WanXMacPoint) SetRoute(str string) PointInterface {
	s.index = int(str[len("wan")]) - '0'
	return s
}
